Hi, my self Ravi Vishwakarma. I have completed my studies at SPICBB Varanasi. now I completed MCA with 76% form Veer Bahadur Singh Purvanchal University Jaunpur.
SWE @ MindStick | Software Engineer | Web Developer | .Net Developer | Web Developer | Backend Engineer | .NET Core Developer
Ravi Vishwakarma
18-Jul-2024The
staticandfinalkeywords serve distinct purposes and are used in different contexts.Here's a detailed explanation of the differences between them:
staticKeywordThe
statickeyword is used to indicate that a member (variable, method, or nested class) belongs to the class itself, rather than to instances of the class.finalKeywordThe
finalkeyword is used to restrict the modification of variables, methods, and classes.Summary of Differences:
staticfinalExample Combining Both Keywords:
You can use both
staticandfinaltogether for class constants:In this example,
MAX_USERSandAPP_NAMEare constants that are shared across all instances of the class and cannot be modified.Read more - Java program to find all pairs of elements in an array whose sum is equal to a given number.